/*
https://leetcode.cn/problems/max-consecutive-ones-iii/
1004. 最大连续1的个数 III
*/

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left = 0, ans = 0,temp = 0;
        for (int rigth = 0; rigth < nums.size(); rigth++){
            if(!nums[rigth]){ temp++;}
            while(temp>k){
                if(!nums[left++]){ temp--;}
            }
            ans = max( ans , rigth - left + 1);
        }
        return ans;
    }
};